using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPCustomersService
    {
        ISession session;

        public MRPCustomersService(ISession session)
        {
            this.session = session;
        }
        public MRPCustomersService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpcustomers(MRPCustomers mrpcustomersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpcustomersX);
            tx.Commit();
        }

        public void UpdateMrpcustomers(MRPCustomers mrpcustomersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpcustomersX);
            tx.Commit();
        }

        public void DeleteMrpcustomers(MRPCustomers mrpcustomersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpcustomersX);
            tx.Commit();
        }

        public IList<MRPCustomers> GetAllMrpcustomers(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPCustomers");
            IList<MRPCustomers> list = query.List<MRPCustomers>();
            if (evict)
            {
                foreach (MRPCustomers s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPCustomers GetAllMrpcustomersByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPCustomers as c where c.Customercode= :x");
            query.SetString("x", id);
            MRPCustomers s = (MRPCustomers)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPCustomers> GetMrpcustomersByQuery(IQuery query, Boolean evict)
        {
            IList<MRPCustomers> list = query.List<MRPCustomers>();
            if (evict)
            {
                foreach (MRPCustomers s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
